﻿using System.Diagnostics;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionMoveAudioRegion : UserActionBase
    {
        // Action description, so we can replay this action (and reverse it)
        public int LayerIndex { get; set; }
        public int RegionUniqueID { get; set; }
        public double MoveOffset { get; set; } // in seconds

        public UserActionMoveAudioRegion()
        {
            Action = UserActionTypes.MoveAudioRegion;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a MoveAudioRegion action");
            foreach (AudioRegion ar in LfsRecordController.project.AudioLayers[LayerIndex].AudioRegions)
            {
                if (ar.UniqueID == RegionUniqueID)
                {
                    ar.TimeOffset -= MoveOffset;
                    break;
                }
            }
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a MoveAudioRegion action");
            foreach (AudioRegion ar in LfsRecordController.project.AudioLayers[LayerIndex].AudioRegions)
            {
                if (ar.UniqueID == RegionUniqueID)
                {
                    ar.TimeOffset += MoveOffset;
                    break;
                }
            }
        }
    }
}
